

#delimit;
set more off;
 

cd "C:\....\Replication files";
	
use "ENMI - replication.dta", clear;


save sims\thresh_results.dta, replace;

forv i=3(1)31{;

use "ENMI - replication.dta", clear;

gen eni_thresh=.;
/*
	replace eni_thresh=1 if ensh_mi<=(`i'+ 2.5) & ensh_mi>=(`i'- 2.5) ;
			replace eni_thresh=0 if eni_thresh==.;
	*/		
	replace eni_thresh=1 if ensh_mi<=`i';
			replace eni_thresh=0 if eni_thresh==.;
		
quietly: xtreg pvote
	1.eni_thresh##1.inc_cab_l
	c.GDPgrowth
	c.moderate
 majelect   pvote_l
if inc_cab_l==1 , fe robust  ;
 
gen thresh=`i';

 gen beta_thresh= _b[1.eni_thresh] if e(sample);
  gen se_thresh= _se[1.eni_thresh] if e(sample);

    
 gen inc_beta_thresh= _b[1.eni_thresh#1.inc_cab_l] if e(sample);
  gen inc_se_thresh= _se[1.eni_thresh#1.inc_cab_l] if e(sample);
 
  
 gen inc_beta= _b[1.inc_cab_l] if e(sample);
  gen inc_se= _se[1.inc_cab_l] if e(sample); 
  
	append using sims\thresh_results.dta;
	save sims\thresh_results.dta, replace;
	
};

#delimit;
use  sims\thresh_results.dta, clear;

gen inc_thresh_hi= beta_thresh + inc_beta_thresh  + inc_beta + 1.68*(se_thresh + inc_se_thresh + inc_se);
gen inc_thresh_lo= beta_thresh + inc_beta_thresh + inc_beta - 1.68*(se_thresh + inc_se_thresh + inc_se);

gen inc=beta_thresh +inc_beta_thresh+ inc_beta;



#delimit;

twoway scatter inc thresh, mcolor(gs4) msize(vsmall)||
	rspike inc_thresh_hi inc_thresh_lo thresh, lcolor(red*1.1) 
	ytitle("Change in % Vote") xtitle("Threshold = 1 if ENMI{&ge} x ")
	yline(0) scheme(s1mono) legend(off) 
	xlabel(5(5)30); 
	

	graph export "figures\FigureA1 - sweet spot.pdf", replace
	

	


